package com.jesper.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jesper.mapper.ItemMapper;
import com.jesper.model.Item;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> {

//    @Autowired
//    ItemCategoryMapper itemCategoryMapper;

    /**
     * 查询商品
     *
     * @param page
     * @param pageSize
     * @param item
     * @return
     */
    public Page<Item> query(int page, int pageSize, Item item) {

        QueryWrapper<Item> wrapper = new QueryWrapper<>();
        Page mPage = new Page<>(page, pageSize);

        wrapper.like(StrUtil.isNotBlank(item.getTitle()), "title", item.getTitle());
        wrapper.eq(item.getCid() != null, "cid", item.getCid());
        wrapper.orderByAsc("updated");

        return this.baseMapper.selectPage(mPage, wrapper);

    }

    /**
     * 查询库存
     *
     * @param page
     * @param pageSize
     * @param item
     * @return
     */
    public Page<Item> queryStock(int page, int pageSize, Item item) {
        QueryWrapper<Item> storeWrapper = new QueryWrapper<>();
        Page sPage = new Page<>(page, pageSize);
        return this.baseMapper.selectPage(sPage, storeWrapper);
    }

    public List<Item> itemList() {
        QueryWrapper<Item> itemWrapper = new QueryWrapper<>();
        return baseMapper.selectList(itemWrapper);

    }
}
